﻿using System;
using System.Collections.Generic;
using System.Linq;
using time;
using myframework._99_热身.time._2011_10_24_scm;



namespace time
{
    public class work_common
    {
        public static string getPhotoPathByProductCode(string ProductCode)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            //DataClasses1DataContext dc = new DataClasses1DataContext();
            var row = dc.w_ProductPhotos.Where(s => s.ProductCode == ProductCode && s.PhotoType == 0 && s.IsMain == 1).FirstOrDefault();
            if (row != null)
            {
                return row.PhotoPath;
            }
            else
            {
                return null;
            }
        }

        public static string getPhotoPath(string productCode, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return "";
            }

            //string photoUrl = Vancl.www.Rules.Config.GerProduct_Pics(productCode, url, 1);
            string photoUrl = "";
            return photoUrl;
        }

        public static string getPhotoPath5(string productCode, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return "";
            }

            //string photoUrl = Vancl.www.Rules.Config.GerProduct_Pics(productCode, url, 3);
            string photoUrl = "";
            photoUrl = GetChangePicture(photoUrl, "250", "250");
            return photoUrl;
        }

        public static string GetChangePicture(string url, string wight, string height)
        {
            if (url.IndexOf(@"http://images.vancl.com") != -1)
            {
                string temp = @"http://images.vancl.com" + "/" + wight + "/" + height + url.Replace(@"http://images.vancl.com", "");
                return temp;
            }
            else
            {
                return url;
            }
        }

        public static string getPhoto(string productCode)
        {
            string url = getPhotoPathByProductCode(productCode);
            string path = getPhotoPath(productCode, url);
            return path;
        }

        public static List<string> GetPhotoPathDirectionByProductCode(string ProductCode)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            var row = dc.w_ProductPhotos.Where(s => s.ProductCode == ProductCode && s.PhotoType != 2).Select(s => s.PhotoPath);

            return row.ToList();
        }

        public static IQueryable<Clothes> GetClothes(string sortOrder, string searchString)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();

            var lc = dc.Clothes.Select(s => s);
            if (!String.IsNullOrEmpty(searchString))
            {
                lc = dc.Clothes.Where(s => s.ProductCode.ToUpper().Contains(searchString.ToUpper())).Take(100);
            }
            else
            {
                lc = dc.Clothes.Take(100);
            }

            switch (sortOrder)
            {
                case "ProductCode":
                    lc = lc.OrderBy(s => s.ProductCode);
                    break;

                case "XPrice":
                    lc = lc.OrderBy(s => s.XPrice);
                    break;

                default:
                    lc = lc.OrderBy(s => s.ProductCode);
                    break;
            }
            return lc;
        }

        public static Clothes GetClothes(string id)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            Clothes clothes = dc.Clothes.Where(m => m.ClothesCode == id).SingleOrDefault();
            return clothes;
        }

        public static IQueryable<City> GetCity()
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            var lc = dc.City.Select(s => s);
            return lc;
        }

        public static void test()
        {
            IEnumerable<string> s = null;
        }
    }
}